package com.cyn.aframework.scriptenginemanager;

import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.util.HashMap;
import java.util.Map;

public class TestGroovy {

    public static void main(String[] args) {
        String regular = "if(hclb=='dkhs') return \"贷款回收红冲\";else if(hclb=='dkff'){return \"贷款发放红冲\";};else {return \"贷款红冲\";}";
        Map<String,Object> argss = new HashMap<>();
        final ScriptEngineManager SCRIPT_ENGINE_MANAGER = new ScriptEngineManager();
        final ScriptEngine engine = SCRIPT_ENGINE_MANAGER.getEngineByName("groovy");
        Bindings bindings = engine.createBindings();


        argss.put("hclb","dkff");
        argss.put("rs","0");
        bindings.putAll(argss);

        try {
            String s =  (String) engine.eval(regular, bindings);
            System.out.println(s);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
